package fr.alma.domo.music.impl;

import org.oasisopen.sca.annotation.Reference;
import org.oasisopen.sca.annotation.Service;

import fr.alma.domo.model.AbstractService;
import fr.alma.domo.music.MusicPlayerSCM;
import fr.alma.domo.music.MusicService;
import fr.alma.domo.music.rc.HP;
import fr.alma.domo.music.rc.Player;

@SuppressWarnings("serial")
@Service(MusicService.class)
public class MusicServiceImpl extends AbstractService implements MusicService {

	private static MusicPlayerSCM MUSIC_PLAYER;
	
	@Reference(name="MusicPlayerSCM")
	public void setMusicPlayerSCM(MusicPlayerSCM musicPlayer){
		MUSIC_PLAYER = musicPlayer;
	}
	
	public MusicServiceImpl(){
		super("MusicService");
	}
	
	@Override
	public void playSong(String client, String title) {
		String position = MUSIC_PLAYER.getPosition(client);
		HP hp = MUSIC_PLAYER.selectHP(position);
		Player player = MUSIC_PLAYER.selectPlayer(title);
		if(player!=null){//FIXME Doit pas être la
			player.setPlayingTitle(title);
		}
		MUSIC_PLAYER.play(client,player, hp);
	}


}
